package com.yuwei.patrol.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.yuwei.base.BaseViewModel
import com.yuwei.http.ApiService
import com.yuwei.http.entity.EditPatrolEntity
import com.yuwei.http.entity.PatrolEntity
import com.yuwei.http.entity.PatrolPointsEntity
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class PatrolViewModel @Inject constructor(
    val apiService: ApiService
): BaseViewModel(){
    val getPatrolSuccess by lazy {
        MutableLiveData<PatrolEntity>()
    }
    val getPatrolPointsSuccess by lazy {
        MutableLiveData<PatrolPointsEntity>()
    }
    val editPatrolSuccess by lazy {
        MutableLiveData<EditPatrolEntity>()
    }
    fun getPatrolList(){
        viewModelScope.launch{
            executeNetwork({
                apiService.getPatrolList()
            },getPatrolSuccess::postValue)
        }
    }
    fun getPatrolPoints(){
        viewModelScope.launch{
            executeNetwork({
                apiService.getPatrolPoints()
            },getPatrolPointsSuccess::postValue)
        }
    }
    fun editPatrol(editPatrolEntity: EditPatrolEntity){
        viewModelScope.launch{
            executeNetwork({
                apiService.postEditPatrol(editPatrolEntity)
            },editPatrolSuccess::postValue)
        }
    }
}